import 'package:flutter/material.dart';
import 'package:flutter_base/config/app_color.dart';
import 'package:flutter_base/generated/assets.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:flutter_base/base/widget/base_get_builder.dart';
import 'package:flutter_base/widgets/button/common_button.dart';
import 'package:flutter_base/widgets/appbar/common_app_bar.dart';
import 'package:flutter_base/widgets/image/auto_image.dart';
import 'package:flutter_base/widgets/textfield/custom_text_field.dart';
import 'forget_password_logic.dart';

class ForgetPasswordPage extends StatelessWidget {
  final logic = Get.put(ForgetPasswordLogic());

  ForgetPasswordPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return BaseGetBuilder<ForgetPasswordLogic>(
      backgroundColor: const Color(0xFFF5F7FA),
      appBar: CommonAppBar(
        title: '',
        showLeft: true,
        leadingImage: Assets.arrowBackWhite,
        leadingImageColor: AppColor.color0C0A09,
      ),
      extendBodyBehindAppBar: true,
      builder: (_) {
        return Stack(
          children: [
            // 背景图
            const Positioned.fill(
              child: AutoImage(
                Assets.accountBg,
                fit: BoxFit.fitWidth,
                alignment: Alignment.topCenter,
              ),
            ),

            SafeArea(
              child: SingleChildScrollView(
                child: Padding(
                  padding: EdgeInsets.symmetric(horizontal: 24.w),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      SizedBox(height: 24.w),
                      _buildHeader(),
                      SizedBox(height: 32.w),
                      _buildEmailInput(),
                      SizedBox(height: 32.w),
                      _buildGetCodeButton(),
                    ],
                  ),
                ),
              ),
            ),
          ],
        );
      },
    );
  }

  // 顶部标题和说明
  Widget _buildHeader() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(
          'Retrieve password',
          style: TextStyle(
            fontSize: 28.sp,
            fontWeight: FontWeight.w600,
            color: AppColor.color0C0A09,
          ),
        ),
        SizedBox(height: 12.w),
        Text(
          'Please enter your email to receive the verification code',
          style: TextStyle(
            fontSize: 14.sp,
            fontWeight: FontWeight.w500,
            color: const Color(0xFF7F909F),
          ),
        ),
      ],
    );
  }

  // 邮箱输入框
  Widget _buildEmailInput() {
    return CustomTextField(
      textEditingController: logic.emailController,
      hintText: 'Please enter your email',
      keyboardType: TextInputType.emailAddress,
      backgroundColor: Colors.white,
    );
  }

  // 获取验证码按钮
  Widget _buildGetCodeButton() {
    return GetBuilder<ForgetPasswordLogic>(
      builder: (controller) {
        return CommonButton.expend(
          title: 'Get verification code',
          type: controller.isButtonEnabled ? ButtonType.primary : ButtonType.disabled,
          onClick: controller.isButtonEnabled ? controller.sendVerificationCode : null,
        );
      },
    );
  }
}
